
﻿﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess.jsp"%>

<c:set var="action" value="${baseURL}/role/addUnit"></c:set>
<c:set var="title" value="新建单位"></c:set>
<c:if test="${requestScope.action=='edit'}">
<c:set var="action" value="${baseURL}/unit/modify"></c:set>
<c:set var="title" value="修改单位"></c:set>
</c:if>
<c:if test="${requestScope.action=='view'}">
<c:set var="title" value="单位详情"></c:set>
</c:if>

<form name="myForm" method="POST" action="${action}">
<input type="hidden" id="id" name="id" value="${obj.id}">
<input type="hidden" id="areaId" name="areaId">
<table id="listTable">
	<tbody>
		<tr>
			<th colspan="3"><img src="${ctx}/static/images/pages/cen/rig/ico_02.png" align="absmiddle">&nbsp;${title}</th>
		</tr>
		<tr>
			<td class="tab_td_all required">单位角色：
				<select class="tab_textbut" id="roleId" name="roleId">
				   <option value="">请选择..</option>
				   <c:forEach var="role" items="${roleList}">
					   <option value="${role.id}" ${unit.role.id==role.id?'selected':''}>${role.roleName}</option>
				   </c:forEach>
			   </select>
			</td>
			<td class="tab_td_all" colspan="2">所属上级单位：
			   	<select class="tab_textbut" id="pid" name="pid">
				   <option value="">请选择..</option>
				   <c:forEach var="un" items="${unitList}">
					   <option value="${un.id}" ${unit.pid==un.id?'selected':''}>${un.unitName}</option>
				   </c:forEach>
			   </select>
			</td>
		</tr>
		
		<tr>
			<td class="tab_td_all required">组织机构代码：
				<input name=unitInstitutionCode type="text" class="tab_textbut" id="unitInstitutionCode" value="${obj.unitInstitutionCode}" size="20" />
			</td>
			<td class="tab_td_all">企业编号：
				<input name=superCompanyCode type="text" class="tab_textbut" id="superCompanyCode" value="${obj.superCompanyCode}" size="20" /></td>
			<td class="tab_td_all required">单位名称：
				<input name=unitName type="text" class="tab_textbut" id="unitName" value="${obj.unitName}" size="20" />
			</td>
		</tr>
		<tr>
			<td class="tab_td_all required">法定代表人：
				<input name=fr type="text" class="tab_textbut" id="fr" value="${obj.fr}" size="20" />
			</td>
			<td class="tab_td_all" colspan="2">产业类别：
				<select class="tab_textbut" id="industryId" name="industryId">
				<option value="0">请选择...</option>
				<c:forEach var="item" items="${industryList}">
					<option value="${item.id}" ${unit.industryId==item.id?'selected':''}>${item.dustryName}</option>
				</c:forEach>
			</select>
		</td>
		</tr>
		<tr>
			<td class="tab_td_all" colspan="3">所在地行政区划：</td>
		</tr>
		
		<tr>
			<td class="tab_td_all">省(自治区、直辖市)：
				<select class="tab_textbut" id="areaId_1" name="provinceId">
				<c:forEach var="item" items="${provinceList}">
					<option value="${item.id}">${item.areaName}</option>
				</c:forEach>
				</select>
			</td>
			<td class="tab_td_all">地(区、市、州、盟)：
				<select class="tab_textbut" id="areaId_2" name="cityId" onchange="getChildArea3($('#areaId_2').val());">
				<option value="">请选择...</option>
					<c:forEach var="item" items="${cityList}">
						<option value="${item.id}" ${areaMap.cityId==item.id?'selected':''}>${item.areaName}</option>
					</c:forEach>
				</select>
			</td>
			<td class="tab_td_all">县(区、市、旗)：
				<select class="tab_textbut" id="areaId_3" name="townId" onchange="getLAreaChildArea($('#areaId_3').val());">
					<option value="">请选择...</option>
					<c:forEach var="item" items="${townList}">
						<option value="${item.id}" ${areaMap.townId==item.id?'selected':''}>${item.areaName}</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		
		<tr>
			<td class="tab_td_all">乡(镇)：
				<select id="lareaId" name="lareaId" class="tab_textbut">
					<option value="">请选择...</option>
					<c:forEach items="${larealist}" var="larea">
					<option value="${larea.id}" ${larea.id==obj.lareaId?'selected':''}>${larea.lareaName}</option>
					</c:forEach>
				</select>
			</td>
			<td class="tab_td_all">村(居)：
			<input name=lareaName type="text" class="button" id="lareaName" value="${obj.lareaName}" size="20" />
			</td>
			<td class="tab_td_all">企业性质：
				<select class="tab_textbut" id="unitProperId" name="unitProper">
				<option value="0">请选择...</option>
				<option value="1" ${unit.unitProper=="1"?'selected':''}>涉海企业</option>
				<option value="2" ${unit.unitProper=="2"?'selected':''}>用海企业</option>
				<option value="3" ${unit.unitProper=="3"?'selected':''}>开发区企业</option>	
				<option value="1,2" ${unit.unitProper=="1,2"?'selected':''}>用海及涉海企业</option>			
				</select>
			</td>
		</tr>
		
		<tr>
			<td class="tab_td_all" colspan="2">单位地址：
			<input name=addr type="text" class="tab_textbut" id="addr" value="${obj.addr}" size="30" /></td>
			<td class="tab_td_all">联系电话：
			<input name=tel type="text" class="tab_textbut" id="tel" value="${obj.tel}" size="20" /></td>
		</tr>
		
		<tr>
			<td class="tab_td_all" colspan="2">企业网址：
			<input name=mobile type="text" class="tab_textbut" id="mobile" value="${obj.mobile}" size="30" /></td>
			<td class="tab_td_all">电子邮箱：
			<input name=fax type="text" class="tab_textbut" id="fax" value="${obj.fax}" size="20" /></td>
		</tr>
		
		<tr>
			<td class="tab_td_all">产品一：
			<input name=product1 type="text" class="tab_textbut" id="product1" value="${obj.product1}" size="20" /></td>
			<td class="tab_td_all">产品二：
			<input name=product2 type="text" class="tab_textbut" id="product2" value="${obj.product2}" size="20" /></td>
			<td class="tab_td_all">产品三：
			<input name=product3 type="text" class="tab_textbut" id="product3" value="${obj.product3}" size="20" /></td>
		</tr>
		
		<tr>
			<td class="tab_td_all" colspan="2">登记注册类型：
				<select name="zclx" class="tab_textbut" id="zclx">
					<option value="">请选择...</option>
					<c:forEach items="${zclxList}" var="zclx">						
						<option value="${zclx}" ${zclx==obj.zclx? 'selected':''}>${zclx}</option>
					</c:forEach>
				</select>
			</td>
			<td class="tab_td_all">国民经济代码：
			<input name=lm type="text" class="tab_textbut" id="lm" value="${obj.lm}" size="20" />
			</td>
		</tr>
		
		<tr>
			<td class="tab_td_all" colspan="3">用海企业坐标：
			经度：
			<input name="kkx" type="text" class="tab_textbut" id="jd" value="${obj.kkx}" size="2" />度
			<input name="kky" type="text" class="tab_textbut" id="jd" value="${obj.kky}" size="2" />分
			<input name="kkz" type="text" class="tab_textbut" id="jd" value="${obj.kkz}" size="2" />秒

			纬度：
				<input name="dlx" type="text" class="tab_textbut" id="wd" value="${obj.dlx}" size="2" />度
				<input name="dly" type="text" class="tab_textbut" id="wd" value="${obj.dly}" size="2" />分
				<input name="dlz" type="text" class="tab_textbut" id="wd" value="${obj.dlz}" size="2" />秒
			</td>
		</tr>
		
		<tr>
			<td class="tab_td_all" colspan="3">企业简介：
				<textarea name=proInfo id="proInfo" cols="60" rows="5">${obj.proInfo}</textarea>
			</td>
		</tr>
		<tr>
		<td class="tab_td_all" align="center" colspan="3">
			<c:if test="${requestScope.action != 'view'}">
			<input type="button" value="提交" class="tab_but" onclick="save()"/>
			</c:if>			
			<input class="tab_but" type="button" value="关闭" 	onclick="closeWin();" />
		</td>	
	</tbody>
</table>

</form>

<script>

$(function(){
	if ("${requestScope.action}"=="create"){	//新建单位时初始化区域列表
		getChildArea2($('#areaId_1').val());
	}

	
	if ("${requestScope.action}"=="view"){		//查看单位信息时转换输入为文本显示
		
		$(":text").each(function(){
			
			if ($(this).val()==""){
				$(this).replaceWith(" ");
			}else{
				$(this).replaceWith($(this).val());
			}
		});
	
		$("select option:selected").each(function(){
			
			if ($(this).val()=="0" || $(this).val()==""){
				$(this).parent().replaceWith(" ");
			}else{
				$(this).parent().replaceWith($(this).text());
			}
			
		});
		
		$("textarea").each(function(){
			
			if ($(this).val()==""){
				$(this).replaceWith(" ");
			}else{
				$(this).replaceWith($(this).val());
			}
			
		});
		
	}else{
		
		$(".required").each(function(){
			$(this).html($(this).html() + "<font color='red'>*</font>");
		});
	}
});


//取得第二级区域
function getChildArea2(pid){
	$("#areaId_3").empty();
	$("#lareaId").empty();
	$("#areaId_3").append( "<option value=''>请选择..</option>" );
	$("#lareaId").append( "<option value=''>请选择..</option>" );
	if(pid=="0"){
		return;
	}
	
	 $.getJSON("${baseURL}/unit/getChildArea?pid=" +pid, function(data) {
			$("#areaId_2").empty();
			$("#areaId_2").append( "<option value=''>请选择..</option>" );
		 	$.each(data, function(i, item) {
	            $("#areaId_2").append( "<option value='" + item.id + "'>" + item.areaName + "</option>" );
	        });
		 	
	 });
}

//取得第三级区域
function getChildArea3(pid){
	$("#lareaId").empty();
	$("#lareaId").append( "<option value=''>请选择..</option>" );
	if(pid=="0"){
		return;
	}
	 $.getJSON("${baseURL}/unit/getChildArea?pid=" +pid, function(data) {
			$("#areaId_3").empty();
			$("#areaId_3").append( "<option value=''>请选择..</option>" );
		 	$.each(data, function(i, item) {
	            $("#areaId_3").append( "<option value='" + item.id + "'>" + item.areaName + "</option>" );
	        });
	 });
}

//获取乡填区域
function getLAreaChildArea(pid){

	 $.getJSON("${baseURL}/unit/getLAreaChildArea?pid=" +pid, function(data) {
			$("#lareaId").empty();
			$("#lareaId").append( "<option value=''>请选择..</option>" );
		 	$.each(data, function(i, item) {
	            $("#lareaId").append( "<option value='" + item.id + "'>" + item.lareaName + "</option>" );
	        });
	 });
}

function validate(){
	var ret = true;
	$(".required").each(function(){
		var fieldName = $(this).text().substring(0, $(this).text().indexOf("："));
		if ($(this).children().val()==""){
			layer.alert("请填写" + fieldName);
			ret = false;
			return false;
		}
	});
	
	return ret;
}

function save(){

	if (validate()){
		
		if ($("#areaId_3").val()!=""&&$("#areaId_3").val()!="0"){
			$("#areaId").val($("#areaId_3").val());
		}else
		if ($("#areaId_2").val()!=""&&$("#areaId_2").val()!="0"){
			$("#areaId").val($("#areaId_2").val());
		}else
		if ($("#areaId_1").val()!=""&&$("#areaId_1").val()!="0"){
			$("#areaId").val($("#areaId_1").val());
		}
		
		myForm.submit();
	}
}

//初始取得第一级区域
//getChildArea1("0");

</script>

<%@ include file="/static/include/bottom.jsp"%>
